package util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class Sql {

    public  Sql()  {}
    private static SqlSessionFactory sqlSessionFactory;
    //类加载时执行
    //sqlsessionUtil工具类在进行第一次加载时，解析xml，创建这个对象
    static {
        try {
            sqlSessionFactory =new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


    public static  SqlSession openSeeion(){
        return sqlSessionFactory.openSession();
    }
}
